package com.lonelyzhe.springboot.utils;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

public class MD5Util {
    public static String md5(String message) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] md5Bytes = md.digest();
            // 采用Base64编码把字节序列转换为明文
            BASE64Encoder base64Encoder = new BASE64Encoder();
            return base64Encoder.encode(md.digest(message.getBytes("utf-8")));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
